﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using Jumpton.SFA.Server.BusinessRule.MasterData;
using Jumpton.SFA.Server.Entity;

public partial class Customer_Product_List_Maintain : PageBase
{
    private int id=0;
    private const string LIST_ID = "id";
    private const string RETURN_PAGE = "Customer_Product_List.aspx";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString[LIST_ID] != null)
        {
            int.TryParse(Request.QueryString[LIST_ID], out id);
        }
        if (!IsPostBack )
        {
            this.FillForm();
        }
    }

    private void FillForm()
    {
        if (id>0)
        {
            CUSTOMER_PRODUCT_LISTS list = new CustomerProductListManager().Load(id);
            if (list != null)
            {
                txtName.Text = list.NAME;
                txtCode.Text = list.CODE;
                this.cbxIsValid.Checked = list.ACTIVE;
                
            }
        }
    }

    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
            CustomerProductListManager listManager = new CustomerProductListManager();
            CUSTOMER_PRODUCT_LISTS list;
            if (id > 0)
            {
                list = listManager.Load(id);
            }
            else
            {
                list = new CUSTOMER_PRODUCT_LISTS();
                list.CREATETIME = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTimeLong(DateTime.Now);

            }
            list.CODE = txtCode.Text;
            list.NAME = txtName.Text;
            list.ACTIVE = cbxIsValid.Checked;
            list.DOMAINID = this.MyStateManager.DomainID;
            list.LAST_UPDATER = this.MyStateManager.Name;
            list.LAST_UPDATE_TIME = Jumpton.SFA.Server.BusinessRule.BusinessLogic.GetDateTimeLong(DateTime.Now);

            
           
            string LogContent = "";

            LogContent += "代码：" + list.CODE +"，";
            LogContent += "描述：" + list.NAME + "，";
            LogContent += "有效：" + list.ACTIVE + "，";
           
            listManager.Save(list);
            Jumpton.SFA.Server.BusinessRule.System.EventManager.CreateNewEvent(
              Jumpton.SFA.Server.BusinessRule.System.LogType.Info_Change, this.MyStateManager.Name,
              this.MyStateManager.UserID, LogContent);
            ShowMessage("保存成功", RETURN_PAGE);
           
        }
        catch (Exception ex)
        {
            ShowMessage("保存失败："+ex.Message);
            Jumpton.SFA.Server.BusinessRule.System.EventManager.CreateNewEvent(
              Jumpton.SFA.Server.BusinessRule.System.LogType.GENERAL_EXCEPTION, this.MyStateManager.Name,
              this.MyStateManager.UserID, "新增客户分销列表 - 异常:" + ex.Message);
        }
    }

    protected void btnCancel_Click(object sender, EventArgs e)
    {
        Response.Redirect(RETURN_PAGE);
    }
}
